// 比例尺
import GridSystem from "./GridSystem"
class ScaleRuler {

    constructor(gls: GridSystem) {
        this.draw(gls);
    }

    draw(gls: GridSystem) {
        let text = `x ${gls.scale.toFixed(2)}`;
        let ctx = gls.ctx;
        let textWidth = ctx.measureText(text).width
        ctx.save()
        ctx.beginPath();

        ctx.moveTo(gls.canvasWidth - 100, gls.canvasHeight - 30);
        ctx.lineTo(gls.canvasWidth - 100, gls.canvasHeight - 20);
        ctx.lineTo(gls.canvasWidth - (50 - textWidth), gls.canvasHeight - 20);
        ctx.lineTo(gls.canvasWidth - (50 - textWidth), gls.canvasHeight - 30);
        ctx.strokeStyle = "#002c8c";
        ctx.stroke();

        ctx.fillStyle = '#002c8c';
        ctx.font = '15px Arial';
        ctx.fillText(text, gls.canvasWidth - 80, gls.canvasHeight - 27);

        ctx.restore()
    }
}

export default ScaleRuler;